package com.example.bbs.mapper;

import com.example.bbs.dto.MessageUser;
import com.example.bbs.pojo.Message;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("insert into message(username, topic, create_time,content) values(#{username},#{topic},now(),#{content}) ")
    void addMessage(Message message);

    @Select("select * from message")
    List<Message> getMessages();

    @Select("select * from message join user on message.username = user.username where message_id = #{id}")
    MessageUser getById(Integer id);

    @Select("select * from message")
    List<Message> list();

    @Delete("delete from message where message_id = #{messageId}")
    void deleteMessage(Integer messageId);
}
